<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 韩金龙
  Date: 2021/11/25
  Time: 9:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
<%--    <link rel="stylesheet" href="css/css.css">--%>
<%--    <link rel="stylesheet" href="css/img.css">--%>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="bootstrap-4.6.0-dist/js/bootstrap.min.js"></script>
</head>
<body>
    <form action="list.do" method="post">
        <input type="hidden" name="pageNum">
        车辆名称:<input type="text" name="cname" value="${map.cname}">
        日租金:<input type="text" name="priceMin" value="${map.priceMin}">-
        <input type="text" name="priceMax" value="${map.priceMax}">
        <input type="submit" value="搜索">
    </form>
    <table class="table table-bordered table-dark">
        <tr>
            <td>车辆编号</td>
            <td>车辆类型</td>
            <td>车辆名称</td>
            <td>车辆图片</td>
            <td>日租金</td>
            <td>折扣</td>
            <td>车辆明细</td>
            <td>操作</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="li">
            <tr>
                <td>${li.cid}</td>
                <td>${li.tname}</td>
                <td>${li.cname}</td>
                <td>
                    <img src="${li.pic}" alt="无法显示" width="50px">
                </td>
                <td>${li.price}</td>
                <td>${li.zk}</td>
                <td>${li.mx}</td>
                <td>
                    <button onclick="del(${li.cid})">删除</button>
                </td>
            </tr>
        </c:forEach>
        <tr>
            <td colspan="20">
                <button onclick="addTo()">添加</button>
                <button onclick="fy(1)">首页</button>
                <button onclick="fy(${pageInfo.isLastPage?1:pageInfo.prePage})">上页</button>
                <button onclick="fy(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下页</button>
                <button onclick="fy(${pageInfo.pages})">尾页</button>
                第${pageInfo.pageNum}/${pageInfo.pages}页
            </td>
        </tr>
    </table>
</body>
<script>
    function fy(pageNum) {
        $("[name='pageNum']").val(pageNum)
        $("form").submit()
    }
    function addTo() {
        location="addTo.do"
    }
    function del(cid) {
        if (confirm("确认删除编号为"+cid+"的数据吗??")){
            $.ajax({
                url:"del.do",
                type:"post",
                data:{"cid":cid},
                dataType:"json",
                success:function(obj) {
                    if (obj>0){
                        alert("删除成功!!")
                        location="list.do";
                    }
                }
            })
        }
    }
</script>
</html>
